//
//  UserAgreementController.m
//  FactorySale
//
//  Created by 主事丫环HU on 2020/8/24.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "UserAgreementController.h"
#import "UserAgreementCell.h"
#import "UserAgreementListModel.h"
#import "UserAgreementWebViewController.h"
@interface UserAgreementController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation UserAgreementController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self requestData];
}
- (void)setupUI{
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = Main_BackGroundColor;
    self.title = @"用户协议";
    
    self.tableView.rowHeight = 70;
    self.tableView.tableFooterView = [[UIView alloc] init];
}
- (void)requestData{
    self.dataArray = [NSMutableArray arrayWithCapacity:0];
    
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    param[@"type"] = @"3"; //1师傅端 2省级 3厂家端 4市县级
    
    [NetWorkTool POST:getAgreementList param:param success:^(id dic) {
        self.dataArray = [UserAgreementListModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];
        [self.tableView reloadData];
    } other:^(id dic) {
    } fail:^(NSError *error) {
    } needUser:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
   return self.dataArray.count;
   
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UserAgreementListModel *model = self.dataArray[indexPath.row];
    UserAgreementCell *cell = [UserAgreementCell cellWithTableView:tableView];
    cell.model = model;
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UserAgreementListModel *model = [self.dataArray safeObjectAtIndex:indexPath.row];

    UserAgreementWebViewController *vc = [[UserAgreementWebViewController alloc] init];
    vc.idStr = model.id;
    [self.navigationController pushViewController:vc animated:YES];
}
@end
